package com.kgcx.organization.service;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.constant.Cons;
import com.kgcx.dbutils.utils.CityUtils;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.organization.domain.Station;
import com.kgcx.organization.mapper.StationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StationService {
    @Autowired
    private StationMapper stationMapper;

    public Station getStation(Long kid) {
        return stationMapper.selectByPrimaryKey(kid);
    }

    public List<Station> getStationList(RequestData rd) {
        Station station = new Station();
        station.setCityId(CityUtils.getCityId(rd));

        PageUtils.page(rd);
        return stationMapper.selectActive(station);
    }

    @Transactional(rollbackFor = Exception.class)
    public void addStation(Station station) {
        stationMapper.insertSelective(station);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateStation(Station station) {
        stationMapper.updateByPrimaryKeySelective(station);
    }

    @Transactional(rollbackFor = Exception.class)
    public void removeStation(Long kid) {
        Station station = new Station();
        station.setKid(kid);
        station.setStatus(Cons.COMMON_STATUS_DELETE);
        stationMapper.updateByPrimaryKeySelective(station);
    }
}
